define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cash_out/index' + location.search,
                    add_url: 'cash_out/add',
                    edit_url: 'cash_out/edit',
                    del_url: 'cash_out/del',
                    multi_url: 'cash_out/multi',
                    import_url: 'cash_out/import',
                    table: 'cash_out',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'ordersn', title: __('Ordersn'), operate: 'LIKE'},
                        {field: 'app.name', title: __('App.name'), operate: false},
                        {field: 'user_id', title: __('User_id'), operate: false},
                        /*{field: 'app_id', title: __('App_id')},*/
                        {field: 'type', title: __('Type'), searchList: {"0":__('Type 0'),"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'price', title: __('Price'), operate: false},
                        {field: 'email', title: __('Email'), operate: false},
                        /*{field: 'admin_id', title: __('Admin_id')},*/
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4')}, formatter: Table.api.formatter.status},

                        {field: 'addtime', title: __('Addtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,sortable: true},
                       /* {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},*/
                        {field: 'updatetime',title: __('Updatetime'),operate: false,sortable: true},
                        {field: 'admin.username', title: __('Admin.username'), operate: false},
                        //{field: 'ext', title: __('Ext'), operate: false},
                        /*{field: 'user.id', title: __('User.id')},*/
                        /*{field: 'user.email', title: __('User.email'), operate: 'LIKE'},*/
                        {field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name:'agree',
                                    text:'同意',
                                    title: __('点击同意'),
                                    icon: 'fa fa-check',
                                    classname: 'btn btn-xs btn-success  btn-ajax',
                                    url:'cash_out/status/val/1',
                                    extend:' target="_blank"',
                                    confirm: __('确认同意提现?'),
                                    hidden:function(row){
                                        if(row.status == 0 && row.type != 2){
                                            return false;
                                        } else {
                                            return true;
                                        }
                                    },
                                    refresh: true

                                },
                                {
                                    name:'refuse',
                                    text:'拒绝',
                                    title: __('点击拒绝'),
                                    icon: 'fa fa-times',
                                    classname: 'btn btn-xs btn-danger btn-ajax',
                                    url:'cash_out/status/val/2',
                                    extend:' target="_blank"',
                                    confirm: __('确认拒绝提现?'),
                                    hidden:function(row){
                                        if(row.status == 0 && row.type != 2){
                                            return false;
                                        } else {
                                            return true;
                                        }
                                    },
                                    refresh: true

                                },
                                {
                                    name:'Pay',
                                    text:'转账',
                                    title: __('点击转账'),
                                    icon: 'fa fa-money',
                                    classname: 'btn btn-xs btn-success  btn-ajax',
                                    url:'cash_out/status/val/3',
                                    extend:' target="_blank"',
                                    confirm: __('确认转账?'),
                                    hidden:function(row){
                                        if(row.status == 0 && row.type == 2){
                                            return false;
                                        } else {
                                            return true;
                                        }
                                    },
                                    refresh: true

                                },
                                {
                                    name:'non',
                                    text:'无效账号',
                                    title: __('无效账号'),
                                    icon: 'fa fa-times',
                                    classname: 'btn btn-xs btn-danger  btn-ajax',
                                    url:'cash_out/status/val/4',
                                    extend:' target="_blank"',
                                    confirm: __('确认账号无效?'),
                                    hidden:function(row){
                                        if(row.status == 0 && row.type == 2){
                                            return false;
                                        } else {
                                            return true;
                                        }
                                    },
                                    refresh: true

                                },

                            ],
                            formatter: Table.api.formatter.operate}

                       /* {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}*/
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});